$(function(){
    $( "#activitiesSearch" ).autocomplete({
        source: function( request, response ) {
            $.ajax({
                url: "http://localhost/PersonalTask/public/Activity/searchService/",
                dataType: "json",
                data: {
                    query: request.term
                },
                success: function( data ) {
                    response( $.map( data.activities, function( item ) {
                        return {
                            label: item.name,
                            value: item.name
                        }
                    }));
                }
            });
        },
        minLength: 1,
        select: function( event, ui ) {
            $("#searchActivityForm").submit();
            console.log( ui.item ? "Selected: " + ui.item.value : "Nothing selected, input was " + this.value);
        },
        open: function() {},
        close: function() {}
    });
});